window.PA = {
  install: function () {
    window.TK && window.TK.click();

    let url = window.PROJECT.ios_url
    let userAgent = navigator.userAgent || navigator.vendor
    if (/android/i.test(userAgent)) {
      url = window.PROJECT.android_url
    }

    if (typeof mraid !== "undefined") {
      try {
        mraid.open(url);
        console.log("mraid open store");
        return;
      } catch {
        console.log("mraid open store error");
      }
    }
    if (typeof dapi !== "undefined") {
      try {
        dapi.openStoreUrl()

        console.log("dapi open store")
        return
      } catch {
        console.log("dapi open store error")

      }
    }
    //打包谷歌UAC平台 也会有FbPlayableAd方法 所以添加一个ad_platform来判断打包得是否是FB来避免打包UAC时进入FB
    if (typeof FbPlayableAd !== "undefined" && (window.PROJECT.ad_platform == "facebook" || window.PROJECT.ad_platform == "moloco")) {
      try {
        FbPlayableAd.onCTAClick()
        console.log("FB || MLC  open store")
        return
      } catch {
        console.log("FB || MLC open store error")
      }
    }
    if (typeof window.BGY_MRAID !== "undefined") {
      try {
        window.BGY_MRAID && window.BGY_MRAID.open()
        console.log("bigo open store")
        return
      } catch {
        console.log("bigo open store error")
      }

      return
    }
    if (typeof window.install == "function") {
      try {
        window.install && window.install()
        console.log("MTG install open store")
        return
      } catch {
        console.log("MTG install open store error")
      }
    }
    if (typeof window.openAppStore == "function") {
      try {
        window.openAppStore()
        console.log("TT openAppStore open store")
        return
      } catch {
        console.log("TT openAppStore open store error")
      }
    }
    if (typeof ExitApi !== "undefined" && typeof ExitApi.exit == "function") {
      try {
        ExitApi.exit && ExitApi.exit();
        console.log("UAC open store")
        return
      } catch {
        console.log("UAC open store error")
      }
    }
    if (typeof window.open == "function" && window.PROJECT.ad_platform == "Inmobi") {//因为Inmobi是谷歌自带得方法 所以判断下平台名
      try {
        window.open && window.open(url);
        console.log("Inmobi open store")
        return
      } catch {
        console.log("Inmobi open store error")
      }
    }
    parent.postMessage("download", "*")
    window.location = url
  },
  end: function () {
    window.TK && window.TK.end();

    if (typeof window.BGY_MRAID !== "undefined") {
      window.BGY_MRAID && window.BGY_MRAID.gameEnd()
    } else if (typeof window.gameEnd == "function") {
      window.gameEnd && window.gameEnd();
    }
    parent.postMessage('complete', '*');
  }
}